package jsqlite;

import com.sangfor.ssl.service.utils.IGeneral;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;

/* loaded from: classes2.dex */
public class JDBCDriver implements Driver {
    public static final int MAJORVERSION = 1;
    private static Constructor makeConn = null;
    public static boolean sharedCache = false;
    public static String vfs;
    protected Connection conn;

    @Override // java.sql.Driver
    public int getMajorVersion() {
        return 1;
    }

    @Override // java.sql.Driver
    public int getMinorVersion() {
        return Constants.drv_minor;
    }

    @Override // java.sql.Driver
    public boolean jdbcCompliant() {
        return false;
    }

    static {
        try {
            Class<?>[] clsArr = {Class.forName("java.lang.String"), clsArr[0], clsArr[0], clsArr[0], clsArr[0]};
            String property = System.getProperty("java.version");
            if (property == null || property.startsWith(IGeneral.OPENSSL_GMv1_0)) {
                throw new java.lang.Exception("unsupported java version");
            }
            String str = "jsqlite.JDBC2y.JDBCConnection";
            if (property.startsWith(IGeneral.OPENSSL_GMv1_1)) {
                str = "jsqlite.JDBC1.JDBCConnection";
            } else {
                if (!property.startsWith("1.2") && !property.startsWith("1.3")) {
                    if (!property.startsWith("1.4")) {
                        try {
                            if (property.startsWith("1.5")) {
                                Class.forName("jsqlite.JDBC2y.JDBCConnection");
                            } else {
                                try {
                                    Class.forName("jsqlite.JDBC2z.JDBCConnection");
                                    str = "jsqlite.JDBC2z.JDBCConnection";
                                } catch (java.lang.Exception unused) {
                                    Class.forName("jsqlite.JDBC2y.JDBCConnection");
                                }
                            }
                        } catch (java.lang.Exception unused2) {
                        }
                    }
                    str = "jsqlite.JDBC2x.JDBCConnection";
                }
                str = "jsqlite.JDBC2.JDBCConnection";
            }
            makeConn = Class.forName(str).getConstructor(clsArr);
            DriverManager.registerDriver(new JDBCDriver());
            try {
                String property2 = System.getProperty("SQLite.sharedcache");
                if (property2 != null && (property2.startsWith("y") || property2.startsWith("Y"))) {
                    sharedCache = Database._enable_shared_cache(true);
                }
            } catch (java.lang.Exception unused3) {
            }
            try {
                String property3 = System.getProperty("SQLite.vfs");
                if (property3 != null) {
                    vfs = property3;
                }
            } catch (java.lang.Exception unused4) {
            }
        } catch (java.lang.Exception e) {
            System.err.println(e);
        }
    }

    @Override // java.sql.Driver
    public boolean acceptsURL(String str) throws SQLException {
        return str.startsWith("jsqlite:/") || str.startsWith("jdbc:jsqlite:/");
    }

    @Override // java.sql.Driver
    public Connection connect(String str, Properties properties) throws SQLException {
        if (acceptsURL(str)) {
            Object[] objArr = new Object[5];
            objArr[0] = str;
            if (properties != null) {
                objArr[1] = properties.getProperty("encoding");
                objArr[2] = properties.getProperty("password");
                objArr[3] = properties.getProperty("daterepr");
                objArr[4] = properties.getProperty("vfs");
            }
            if (objArr[1] == null) {
                objArr[1] = System.getProperty("SQLite.encoding");
            }
            if (objArr[4] == null) {
                objArr[4] = vfs;
            }
            try {
                Connection connection = (Connection) makeConn.newInstance(objArr);
                this.conn = connection;
                return connection;
            } catch (InvocationTargetException e) {
                throw new SQLException(e.getTargetException().toString());
            } catch (java.lang.Exception e2) {
                throw new SQLException(e2.toString());
            }
        }
        return null;
    }

    @Override // java.sql.Driver
    public DriverPropertyInfo[] getPropertyInfo(String str, Properties properties) throws SQLException {
        return new DriverPropertyInfo[]{new DriverPropertyInfo("encoding", ""), new DriverPropertyInfo("password", ""), new DriverPropertyInfo("daterepr", "normal"), new DriverPropertyInfo("vfs", vfs)};
    }
}
